package com.hc.acoustics.ui.activity

import android.content.Intent
import android.os.Bundle
import com.hc.acoustics.R
import com.hc.acoustics.base.BaseActivity
import com.hc.acoustics.util.FormulaUtil
import com.yc.yclibrary.base.YcAppCompatActivity
import kotlinx.android.synthetic.main.formula_button.*
import kotlinx.android.synthetic.main.type5_formula1_location_activity.*
import kotlinx.android.synthetic.main.type5_formula2_location_activity.*
import java.lang.NumberFormatException

/**
 *  五超低音阵列 - 超低音心形指向简单计算①
 */
class Type5Formula2Activity : BaseActivity() {

    companion object {
        private const val KEY_TITLE = "key_title"
        @JvmStatic
        fun newInstance(activity: YcAppCompatActivity, title: String) {
            val intent = Intent(activity, Type5Formula2Activity::class.java)
            intent.putExtra(KEY_TITLE, title)
            activity.startActivity(intent)
        }
    }

    override fun getLayoutId(): Int {
        return R.layout.type5_formula2_location_activity
    }

    override fun initView(savedInstanceState: Bundle?) {
        setActionBar(intent.getStringExtra(KEY_TITLE))
        formulaResetBtn.setOnClickListener {
            formula5_2_f_TEV.reset()
            formula5_2_d_TEV.reset()
            formula5_2_c_TEV.reset()
        }
        formulaOkBtn.setOnClickListener {
            try {
                val resultD = FormulaUtil.formula5_2_1(formula5_2_f_TEV.getDouble())
                val resultT = FormulaUtil.formula5_2_2(formula5_2_f_TEV.getDouble())
                formula5_2_d_TEV.setText(resultD)
                formula5_2_c_TEV.setText(resultT)
            } catch (e: NumberFormatException) {
                formula5_2_d_TEV.setText("Infinity")
                formula5_2_c_TEV.setText("Infinity")
            }
        }
    }
}